import requestService from "./httpRequest";
import { netUrl } from "./url.js";
const PROD_SERVICE = netUrl;
const DEV_SERVICE = netUrl;
// const PROD_SERVICE = "https://我的线上产品域名/lawyer-card-service";
// const DEV_SERVICE = "http://localhost:8081/lawyer-card-service";

/**
 * 根据开发环境返回接口url
 * @returns {string}
 */
function getSerive() {
  if (process.env.NODE_ENV === "production") {
    return PROD_SERVICE;
  } else {
    return DEV_SERVICE;
  }
}

/** wx.request服务封装 */
export default {
  /**
   * 检查微信Token是否还生效
   * @param data
   * @param callBack
   */
  http(url, type, data, callBack, failCallBack) {
    requestService
      .sendRequest()
      .url(
        url.indexOf("https://") === -1 || url.indexOf("http://") === -1
          ? getSerive() + url
          : url
      )
      .method(type)
      .data(data)
      .success((res) => {
        callBack(res);
      })
      .fail((res) => {
        if (failCallBack) failCallBack(res);
      })
      .send();
  },
};
